package com.ilovepostcard.controller.server;

import java.util.ArrayList;

import com.ilovepostcard.utils.StringUtils;

public class PostcardRequest {

    private String mAction;
    private ArrayList<QueryItem> mParams;

    public static PostcardRequest createRequestForUserLogin(String uname, String pwd) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.UserLogin.ACTION);
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.UserLogin.PARAM_UNAME_URLENCODE, uname));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UserLogin.PARAM_PWD, pwd));
        return request;
    }
    
    public static PostcardRequest createRequestForUserRegister(String uname, String pwd, String nickname) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.UserRegister.ACTION);
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.UserRegister.PARAM_UNAME_URLENCODE, uname));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UserRegister.PARAM_PWD, pwd));
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.UserRegister.PARAM_NICK_NAME_URLENCODE, nickname));
        return request;
    }
    
    public static PostcardRequest createRequestForUserLoginFromOpen(String uname, String nickname, int type) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.UserLoginFromOpen.ACTION);
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.UserLoginFromOpen.PARAM_UNAME_URLENCODE, uname));
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.UserLoginFromOpen.PARAM_NICK_NAME_URLENCODE, nickname));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UserLoginFromOpen.PARAM_TYPE, type+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetUserInfo(String uname, long uid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetUserInfo.ACTION);
        if (StringUtils.isNotBlank(uname))
            request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.GetUserInfo.PARAM_UNAME_URLENCODE, uname));
        if (uid > 0)
            request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetUserInfo.PARAM_UID, uid+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetRecommendPostcard(long uid, int pi, int pc) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetPostcard.ACTION_RECOMMEND);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcard.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcard.PARAM_PI, pi+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcard.PARAM_PC, pc+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetFriendPostcard(long uid, int pi, int pc) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetPostcard.ACTION_FRIEND);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcard.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcard.PARAM_PI, pi+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcard.PARAM_PC, pc+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetMyPostcard(long uid, int pi, int pc) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetPostcard.ACTION_MY);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcard.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcard.PARAM_PI, pi+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcard.PARAM_PC, pc+""));
        return request;
    }
    
    public static PostcardRequest createRequestForSearchPostcard(String keyword, int pi, int pc) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetPostcard.ACTION_SEARCH_POSTCARD);
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.GetPostcard.PARAM_K_URLENCODE, keyword));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcard.PARAM_PI, pi+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcard.PARAM_PC, pc+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetUploadSKey() {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetUploadSKey.ACTION);
        return request;
    }
    
    public static PostcardRequest createRequestForUploadFile(int type, String fileName, String skey, long uid, int x, int y, int w,int h, int r) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.UploadFile.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UploadFile.PARAM_TYPE, type+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UploadFile.PARAM_FILENAME, fileName));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UploadFile.PARAM_SKEY, skey));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UploadFile.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UploadFile.PARAM_X, x+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UploadFile.PARAM_Y, y+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UploadFile.PARAM_W, w+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UploadFile.PARAM_H, h+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UploadFile.PARAM_R, r+""));
        return request;
    }
    
    public static PostcardRequest createRequestForCanModifyNickname(long uid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.CanModifyNickname.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CanModifyNickname.PARAM_UID, uid+""));
        return request;
    }
    
    public static PostcardRequest createRequestForUpdateUserInfo(long uid,
            int sex, String birthday, String province, String city,
            String introduction, String nickname) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.UpdateUserInfo.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UpdateUserInfo.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UpdateUserInfo.PARAM_SEX, sex+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UpdateUserInfo.PARAM_BIRTHDAY, birthday));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UpdateUserInfo.PARAM_PROVINCE, province));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.UpdateUserInfo.PARAM_CITY, city));
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.UpdateUserInfo.PARAM_INTRODUCTION_URLENCODE, introduction));
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.UpdateUserInfo.PARAM_NICKNAME_URLENCODE, nickname));
        return request;
    }
    
    public static PostcardRequest createRequestForListCity() {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.ListCity.ACTION);
        return request;
    }
    
    public static PostcardRequest createRequestForCreatePostcard(long uid, String location,
            String tofriendswords, String story, boolean isshowwords,
            double latitude, double longitude, String skey, int viewPermission,
            int locationPermission, String tags) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.CreatePostcard.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CreatePostcard.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.CreatePostcard.PARAM_LOCATION_URLENCODE, location));
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.CreatePostcard.PARAM_TO_FRIEND_WORDS_URLENCODE, tofriendswords));
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.CreatePostcard.PARAM_STORY_URLENCODE, story));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CreatePostcard.PARAM_IS_SHOW_WORDS, (isshowwords?0:1)+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CreatePostcard.PARAM_LATITUDE, latitude+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CreatePostcard.PARAM_LONGITUDE, longitude+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CreatePostcard.PARAM_SKEY, skey));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CreatePostcard.PARAM_VIEW_PERMISSION, viewPermission+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CreatePostcard.PARAM_LOCATION_PERMISSION, locationPermission+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CreatePostcard.PARAM_TAGS, tags));
        return request;
    }
    
    public static PostcardRequest createRequestForDeletePostcard(long pid, long uid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.DeletePostcard.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.DeletePostcard.PARAM_PID, pid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.DeletePostcard.PARAM_UID, uid+""));
        return request;
    }
    
    public static PostcardRequest createRequestForPostProposal(long uid, String body) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.PostProposal.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.PostProposal.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.PostProposal.PARAM_BODY_URLENCODE, body));
        return request;
    }
    
    public static PostcardRequest createRequestForCheckNew(String ver, String channel) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.CheckNew.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CheckNew.PARAM_VER, ver));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CheckNew.PARAM_CHANNEL, channel));
        return request;
    }
    
    public static PostcardRequest createRequestForAttention(long uidMy, long uidOther, int type) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.Attention.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.Attention.PARAM_UID_MY, uidMy+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.Attention.PARAM_UID_OTHER, uidOther+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.Attention.PARAM_TYPE, type+""));
        return request;
    }
    
    public static PostcardRequest createRequestForCheckAttention(long uidMy, long uidOther) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.CheckAttention.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CheckAttention.PARAM_UID_MY, uidMy+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CheckAttention.PARAM_UID_OTHER, uidOther+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetAttentionList(long uid, int type, int pi, int pc) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetAttentionList.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetAttentionList.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetAttentionList.PARAM_TYPE, type+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetAttentionList.PARAM_PI, pi+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetAttentionList.PARAM_PC, pc+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetPostcardInfo(long pid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetPostcardInfo.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcardInfo.PARAM_PID, pid+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetUserActiveTime(long uid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetUserActiveTime.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetUserActiveTime.PARAM_UID, uid+""));
        return request;
    }
    
    public static PostcardRequest createRequestForLikePostcard(long uid, long pid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.LikePostcard.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.LikePostcard.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.LikePostcard.PARAM_POSTCARDID, pid+""));
        return request;
    }
    
    public static PostcardRequest createRequestForNewPostcardComment(long uid, long pid, String body) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.NewPostcardComment.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.NewPostcardComment.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.NewPostcardComment.PARAM_POSTCARDID, pid+""));
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.NewPostcardComment.PARAM_BODY_URLENCODE, body));
        return request;
    }
    
    public static PostcardRequest createRequestForGetPostcardComments(long pid, int pi, int pc) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetPostcardComments.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcardComments.PARAM_POSTCARDID, pid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcardComments.PARAM_PI, pi+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetPostcardComments.PARAM_PC, pc+""));
        return request;
    }
    
    public static PostcardRequest createRequestForSearchUser(String k, int pi, int pc) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.SearchUser.ACTION);
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.SearchUser.PARAM_K_URLENCODE, k));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.SearchUser.PARAM_PI, pi+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.SearchUser.PARAM_PC, pc+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetNewMessageCount(long uid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetNewMessageCount.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetNewMessageCount.PARAM_UID, uid+""));
        return request;
    }
    
    public static PostcardRequest createRequestForDeleteMessage(long uid, long mid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.DeleteMessage.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.DeleteMessage.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.DeleteMessage.PARAM_MID, mid+""));
        return request;
    }
    
    public static PostcardRequest createRequestForListMessage(long uid, int pi, int pc) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.ListMessage.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.ListMessage.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.ListMessage.PARAM_PI, pi+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.ListMessage.PARAM_PC, pc+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetUserHeadImg(long uid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetUserHeadImg.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetUserHeadImg.PARAM_UID, uid+""));
        return request;
    }
    
    public static PostcardRequest createRequestForListAddress(long uid, int pi, int pc) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.ListAddress.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.ListAddress.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.ListAddress.PARAM_PI, pi+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.ListAddress.PARAM_PC, pc+""));
        return request;
    }
    
    public static PostcardRequest createRequestForNewAddress(long uid, String name, String telephone, String province, String city, String address, String zipcode) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.NewAddress.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.NewAddress.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.NewAddress.PARAM_NAME_URLENCODE, name));
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.NewAddress.PARAM_TELEPHONE_URLENCODE, telephone));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.NewAddress.PARAM_PROVINCE, province));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.NewAddress.PARAM_CITY, city));
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.NewAddress.PARAM_ADDRESS_URLENCODE, address));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.NewAddress.PARAM_ZIPCODE, zipcode));
        return request;
    }
    
    private static String contactArray(long[] array) {
        if (array != null && array.length > 0) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < array.length; i++) {
                sb.append(array[i]);
                if (array.length - 1 != i) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }
        return null;
    }
    
    public static PostcardRequest createRequestForNewOrder(String type, long uid, long[] pids, String sendword, long[] aids) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.NewOrder.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.NewOrder.PARAM_TYPE, type));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.NewOrder.PARAM_UID, uid+""));
        String pidsparam = contactArray(pids);
        if (pidsparam != null) {
            request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.NewOrder.PARAM_PIDS, pidsparam));
        }
        request.addQueryItem(QueryItem.createURLEncodeQueryItem(ServerSpec.NewOrder.PARAM_SENDWORD_URLENCODE, sendword));
        String aidsparam = contactArray(aids);
        if (aidsparam != null) {
            request.addQueryItem(QueryItem.createQueryItem(ServerSpec.NewOrder.PARAM_AIDS, aidsparam));
        }
        return request;
    }
    
    public static PostcardRequest createRequestForListOrder(long uid, int pi, int pc) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.ListOrder.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.ListOrder.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.ListOrder.PARAM_PI, pi+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.ListOrder.PARAM_PC, pc+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetOrderInfo(long oid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetOrderInfo.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetOrderInfo.PARAM_OID, oid+""));
        return request;
    }
    
    public static PostcardRequest createRequestForCheckLike(long uid, long pid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.CheckLike.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CheckLike.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.CheckLike.PARAM_PID, pid+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetShareTextConfig(int type, long uid, long pid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetShareTextConfig.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetShareTextConfig.PARAM_TYPE, type+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetShareTextConfig.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetShareTextConfig.PARAM_PID, pid+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetLastPostcardComment(long uid, long pid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetLastPostcardComment.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetLastPostcardComment.PARAM_UID, uid+""));
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetLastPostcardComment.PARAM_PID, pid+""));
        return request;
    }
    
    public static PostcardRequest createRequestForGetBuycartUrl(long uid) {
        PostcardRequest request = new PostcardRequest();
        request.setAction(ServerSpec.GetBuycartUrl.ACTION);
        request.addQueryItem(QueryItem.createQueryItem(ServerSpec.GetBuycartUrl.PARAM_UID, uid+""));
        return request;
    }
    
    /**
     * eg: do=UserLogin&uname=&pwd=
     * @return
     */
    public String getRequestString() {
        StringBuilder sb = new StringBuilder();
        sb.append("do=") .append(mAction);
        if (mParams != null) {
            for (QueryItem item : mParams) {
                sb.append("&").append(item.toString());
            }
        }
        return sb.toString();
    }

    private void setAction(String action) {
        mAction = action;
    }

    private void addQueryItem(QueryItem item) {
        if (mParams == null)
            mParams = new ArrayList<QueryItem>();
        mParams.add(item);
    }
}
